#****************************************************************************
#
#	COPYRIGHT(C) MAXSI SOFTWARE, JONAS 'SORTIE' TERMANSEN 2008, 2009, 2010
#
#	This file is part of Maxsi Feedback.
#
#	Maxsi Feedback is free software: you can redistribute it and/or modify
#	it under the terms of the GNU Lesser General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#
#	Maxsi Feedback is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#	GNU Lesser General Public License for more details.
#
#	You should have received a copy of the GNU Lesser General Public License
#	along with Maxsi Feedback. If not, see <http://www.gnu.org/licenses/>.
#
#	MaxsiFeedback.dll
#	A linkable version of Maxsi Feedback
#
#	MaxsiFeedback.mak
#	Makefile for the entire Maxsi Feedback!
#
#****************************************************************************
#
# Use of gcc with *.cpp files implicitly causes c++ compilation - but not 
# always. Use of g++ ensures explicit c++ compilation.
# Define all rules with a <TAB> character and NOT spaces. 
#
# This makefile automatically finds all source files based on file extension in 
# the source subdirectory and outputs compiled object (*.o) to the release 
# subdirectory.
# The same process is performed to convert resource scripts (*.rc) to 
# resource objects (*.res). The objects, source and resource, are then
# linked into the final executable.
#
# When invoking make, any of the macros defined in the makefile can be
# overridden if passed as command line parameters. For example, to specify the
# executable name (the quotes, "", are optional):
#
#        make EXENAME="another_test.exe" -f makefile.mak 
#
# This makefile does not produce or use dependency information and therefore
# can only be used for complete builds in its present form.
#------------------------------------------------------------------------------
#define the compilers to be used. CXX is defined by make as g++; CC does not
#seem to be defined as gcc
CC       = g++
WNDRES   = windres
#------------------------------------------------------------------------------
#first name the (i)output dir (ii) include dir and (iii) resources dir
BINDIR   = bin32
OUTDIR   = $(BINDIR)
SRCDIR   = MaxsiFeedback
RESDIR   = MaxsiFeedback
OBJDIR   = $(SRCDIR)/Release
#------------------------------------------------------------------------------
#name the final exe
EXENAME   = MaxsiFeedback.exe
#and the source extension
SRCEXT    = .cpp
OBJEXT    = .o
RCEXT     = .rc
ROBJEXT   = .resobj
#------------------------------------------------------------------------------
#include some variables from the projects we depend on
include Makefiles/MaxsiEngineDependencies.mak
include Makefiles/MaxsiDistributionDependencies.mak
#------------------------------------------------------------------------------
#name the source files and compiled objects
SRC      := $(wildcard $(SRCDIR)/*$(SRCEXT))
APPOBJS  := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%,$(subst $(SRCEXT),$(OBJEXT),$(SRC)))
#------------------------------------------------------------------------------
#name resource scripts and compiled resource objects
RSRC     := $(wildcard $(RESDIR)/*.rc)
RESOBJS  := $(patsubst $(RESDIR)/%,$(OBJDIR)/%,$(subst $(RCEXT),$(ROBJEXT),$(RSRC)))
#------------------------------------------------------------------------------
#finally set various flags for compiling, linking or building
#-DWIN32_LEAN_AND_MEAN 
PREPROC  = 
CPPFLAGS = -Wall -Wno-write-strings -c -O2 $(PREPROC) -IMaxsiEngine
LFLAGS   = -s -static-libgcc
RFLAGS   = -O COFF
#Note that -Wl,--subsystem,windows is synonymous with -mwindows; -Wl is used
#to ensure that linker switches are passed to the linker when it (ld) is
#invoked by another program, eg gcc. Both have the effect of building a 
#windows app ie. no console window.
LIBS     = -mwindows $(BINDIR)/zlib1.dll lib/libws2_32.a lib/libcomctl32.a lib/libole32.a lib/libmswsock.a bin32/MaxsiEngine.dll
#------------------------------------------------------------------------------
#main rule to compile the whole program ('all' - the first rule - is 
#called/invoked by default).
#link all compiled source and resource objects to produce final exe in
#output dir
all: $(OUTDIR) $(OBJDIR) $(APPOBJS) $(RESOBJS)
	$(CC) $(LFLAGS) -o $(OUTDIR)/$(EXENAME) $(APPOBJS) $(RESOBJS) $(LIBS)

#create the output directory
$(OUTDIR):
	@-mkdir $(OUTDIR)

#create the obj directory
$(OBJDIR):
	@-mkdir $(OBJDIR)

# MaxsiInstall headers
MIINCS = 
#compile all source files in Source dir to object (o) files in output dir
$(OBJDIR)/%$(OBJEXT):$(SRCDIR)/%$(SRCEXT) $(MEINCS) $(MDINCS)
	$(CC) $(CPPFLAGS) $< -o $@


#compile resource object(s) from Resources dir to object (res) files in 
#output dir
$(OBJDIR)/%$(ROBJEXT):$(RESDIR)/%$(RCEXT)
	$(WNDRES) --include-dir $(RESDIR) $(RFLAGS) $< -o $@


#==============================================================================
#cleanup
clean:
	-rm $(APPOBJS) $(RESOBJS)

cleanall:
	-rm -r $(OUTDIR)
	
run:
	$(OUTDIR)/$(EXENAME)
#==============================================================================	
.PHONY: all clean cleanall run
#==============================================================================
